package com.xxxt.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xxxt.dao.StudentMapper;
import com.xxxt.entity.Student;

import java.util.List;
import java.util.concurrent.Semaphore;

/**
 * 
 * @author huangrusiehng
 *
 */
@Transactional
public class Thread1 implements Runnable{
    private final Semaphore parallel = new Semaphore(10);
    private StudentMapper studentMapper;
    private List<Student> list;

    public Thread1(List<Student> list,StudentMapper studentMapper){
    	this.studentMapper=studentMapper;
        this.list = list;
    }

    @Override
    public void run() {
        synchronized(this){
            try {
            	for (Student student : list) {
					studentMapper.addStudent(student);
				}
                parallel.acquire();
                System.out.println("当前剩余通道数="+parallel.availablePermits());
                parallel.release();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    

}